home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / InputEvent.java < prev    next >
Text File  |  1998-09-22  |  4KB  |  148 lines

  1. /*
  2.  * @(#)InputEvent.java    1.12 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.event;
  16.  
  17. import java.awt.Event;
  18. import java.awt.Component;
  19.  
  20. /**
  21.  * The root event class for all component-level input events.
  22.  *
  23.  * Input events are delivered to listeners before they are
  24.  * processed normally by the source where they originated.
  25.  * This allows listeners and component subclasses to "consume"
  26.  * the event so that the source will not process them in their
  27.  * default manner.  For example, consuming mousePressed events
  28.  * on a Button component will prevent the Button from being
  29.  * activated.
  30.  *
  31.  * @version 1.12 07/01/98
  32.  * @author Carl Quinn
  33.  */
  34. public abstract class InputEvent extends ComponentEvent {
  35.  
  36.     /**
  37.      * The shift key modifier constant.
  38.      */
  39.     public static final int SHIFT_MASK = Event.SHIFT_MASK;
  40.  
  41.     /**
  42.      * The control key modifier constant.
  43.      */
  44.     public static final int CTRL_MASK = Event.CTRL_MASK;
  45.  
  46.     /** 
  47.      * The meta key modifier constant.
  48.      */
  49.     public static final int META_MASK = Event.META_MASK;
  50.  
  51.     /** 
  52.      * The alt key modifier constant.
  53.      */
  54.     public static final int ALT_MASK = Event.ALT_MASK;
  55.  
  56.     /**
  57.      * The mouse button1 modifier constant.
  58.      */
  59.     public static final int BUTTON1_MASK = 1 << 4;
  60.  
  61.     /**
  62.      * The mouse button2 modifier constant.
  63.      */
  64.     public static final int BUTTON2_MASK = Event.ALT_MASK;
  65.  
  66.     /** 
  67.      * The mouse button3 modifier constant.
  68.      */
  69.     public static final int BUTTON3_MASK = Event.META_MASK;
  70.  
  71.     long when;
  72.     int modifiers;
  73.  
  74.     /**
  75.      * Constructs an InputEvent object with the specified source component,
  76.      * modifiers, and type.
  77.      * @param source the object where the event originated
  78.      * @id the event type
  79.      * @when the time the event occurred
  80.      * @modifiers the modifier keys down while event occurred
  81.      */
  82.     InputEvent(Component source, int id, long when, int modifiers) {
  83.         super(source, id);
  84.         this.when = when;
  85.         this.modifiers = modifiers;
  86.     }
  87.  
  88.     /**
  89.      * Returns whether or not the Shift modifier is down on this event.
  90.      */
  91.     public boolean isShiftDown() {
  92.         return (modifiers & Event.SHIFT_MASK) != 0;
  93.     }
  94.  
  95.     /**
  96.      * Returns whether or not the Control modifier is down on this event.
  97.      */
  98.     public boolean isControlDown() {
  99.         return (modifiers & Event.CTRL_MASK) != 0;
  100.     }
  101.  
  102.     /**
  103.      * Returns whether or not the Meta modifier is down on this event.
  104.      */ 
  105.     public boolean isMetaDown() {
  106.         return (modifiers & Event.META_MASK) != 0;
  107.     }
  108.  
  109.     /**
  110.      * Returns whether or not the Alt modifier is down on this event.
  111.      */ 
  112.     public boolean isAltDown() {
  113.         return (modifiers & Event.ALT_MASK) != 0;
  114.     }
  115.  
  116.  
  117.     /**
  118.      * Returns the timestamp of when this event occurred.
  119.      */
  120.     public long getWhen() {
  121.         return when;
  122.     }
  123.  
  124.     /**
  125.      * Returns the modifiers flag for this event.
  126.      */
  127.     public int getModifiers() {
  128.         return modifiers;
  129.     }
  130.  
  131.     /**
  132.      * Consumes this event so that it will not be processed
  133.      * in the default manner by the source which originated it.
  134.      */
  135.     public void consume() {
  136.         consumed = true;
  137.     }
  138.  
  139.     /**
  140.      * Returns whether or not this event has been consumed.
  141.      * @see #consume
  142.      */
  143.     public boolean isConsumed() {
  144.         return consumed;
  145.     }
  146.  
  147. }
  148.